
//
//  AppDelegate.m
//  GSG
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "MainPageViewController.h"
#import "MusicLibraryViewController.h"
#import "RightViewController.h"
#import <ShareSDK/ShareSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "WXApi.h"
#import "WeiboApi.h"
#import "WeiboSDK.h"
#import "AFNetworking.h"
#import <AVFoundation/AVFoundation.h>
#import"singleSong.h"
#import"SongModel.h"
#import"AFSoundManager.h"
#import"AFAudioRouter.h"
#import"Singleton.h"
@interface AppDelegate ()
@property(nonatomic,retain)UISlider *slider1;//歌曲进度slider
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,assign)NSInteger num;
@property(nonatomic,assign)NSInteger flag;
@property (nonatomic, retain)UILabel *elapsedTime;//已经播放的时间
@property (nonatomic, retain)UILabel *Time;//总时间的时间
@property (nonatomic, retain)UILabel *elapsedTime1;//已经播放的时间
@property (nonatomic, retain)UILabel *Time1;//总时间的时间
@property(nonatomic,retain)UIButton*button;
@property (nonatomic, retain)UIButton *shareButton;//第三方分享
@property(nonatomic,retain)UIButton* collect;  // 收藏
@property(nonatomic,retain)UIButton *palyType;//播放类型
@property(nonatomic,retain)UIButton *bunext;
@property (nonatomic, retain)UIButton *playButton;//播放按钮
@property(nonatomic,retain)UIButton *bu;
@property (nonatomic, retain)UILabel *timeRemaining;//剩余的时间
@property(nonatomic,assign)NSInteger flag2;//实现单曲循环的值
@property(nonatomic,assign)NSInteger flag3;//实现随机播放的值
@property(nonatomic,assign)NSInteger flag1;
@property(nonatomic,retain)UISlider *slider;
@property(nonatomic,retain)UILabel *songLabel;//歌曲的名字
@property(nonatomic,retain)UILabel *singerLabel;//歌手的名字
@property(nonatomic,retain)UILabel *songLabel1;//歌曲的名字
@property(nonatomic,retain)UILabel *singerLabel1;//歌手的名字
@property(nonatomic,retain)SongModel *song;
@property(nonatomic,retain)UIAlertView *alterRefuse;
@property(nonatomic,retain)UIAlertView *alterRandom;
@property(nonatomic,retain)UIAlertView *alterOrder;
@property(nonatomic,retain)UIButton *play;
@end

@implementation AppDelegate
-(instancetype)init{
    if (self) {
        _flag=0;
        _flag1=0;
        self.arr=[[NSMutableArray alloc]init];
    }
    return self;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    // 设置开启图片存在时间
      [NSThread sleepForTimeInterval:2.5];
    
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
    
    // 激活
    [session setActive:YES error:nil];


    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
   
    self.window.backgroundColor = [UIColor whiteColor];
   
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
   
    UIAlertView *noNet=[[UIAlertView   alloc]initWithTitle:@"当前无网络" message:@"请您确认手机是否联网" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    
    [self.window addSubview:noNet];
    
    UIAlertView *selfNet=[[UIAlertView   alloc]initWithTitle:@"网络提示" message:@"当前为自身流量请您慎重使用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    
    [self.window addSubview:selfNet];
    
    // 2.设置网络状态改变后的处理
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        // 当网络状态改变了, 就会调用这个block
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: // 未知网络
                NSLog(@"未知网络");
                break;
                
            case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
            
                             NSLog(@"没有网络(断网)");
                [ noNet show];

                break;
                
            case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
                NSLog(@"手机自带网络");
                break;
                
            case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
                NSLog(@"WIFI");
                
                break;
        }
    }];
    
    // 3.开始监控
    [mgr startMonitoring];
    
    
    
    
    // 孙总专用
    MainPageViewController *mainVC = [[MainPageViewController alloc] init];


   // self.window.rootViewController = mainVC;
//    UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC];

//    self.window.rootViewController = mainVC;
    UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC];

    
//    RightViewController *leftView = [[[RightViewController alloc] init] autorelease];

//    UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC];
//    //透明导航栏 需要添加一个图片
//    
    [mainNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"beijing0.png"] forBarMetrics:UIBarMetricsCompact];
    mainNav.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    mainNav.extendedLayoutIncludesOpaqueBars = YES;

    






    self.window.rootViewController = mainNav;
    
    //透明导航栏 需要添加一个图片
//    [mainNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"1398247929.jpg"] forBarMetrics:UIBarMetricsCompact];
//    mainNav.navigationBar.barStyle = UIBarStyleBlackTranslucent;
//    mainNav.extendedLayoutIncludesOpaqueBars = YES;





//    [mainVC release];
//    [mainNav release];
//    RightViewController *leftView = [[[RightViewController alloc] init] autorelease];

    
//    IIViewDeckController *vc = [[IIViewDeckController alloc] initWithCenterViewController:mainNav rightViewController:leftView];
//    vc.view.backgroundColor = [UIColor whiteColor];
    
//    vc.rightSize =  (50);
    
//    self.viewDeckController = vc;
//    self.window.rootViewController = self.viewDeckController;
    [self.window makeKeyAndVisible];
    
    
     [self performSelector:@selector(showWord1) withObject:nil afterDelay:0.0f];
    
    [ShareSDK registerApp:@"7232870fdc6e"];//字符串api20为您的ShareSDK的AppKey
    
    //添加新浪微博应用 注册网址 http://open.weibo.com
    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                             redirectUri:@"http://www.sharesdk.cn"];
    //添加腾讯微博应用 注册网址 http://dev.t.qq.com
    [ShareSDK connectTencentWeiboWithAppKey:@"801307650"
                                  appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
                                redirectUri:@"http://www.sharesdk.cn"
                                   wbApiCls:[WeiboApi class]];
    
    
//    //添加QQ应用  注册网址  http://open.qq.com/
//    [ShareSDK connectQQWithQZoneAppKey:@"100371282"
//                     qqApiInterfaceCls:[QQApiInterface class]
//                       tencentOAuthCls:[TencentOAuth class]];
//    
//    //添加微信应用 注册网址 http://open.weixin.qq.com
//    [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
//                           wechatCls:[WXApi class]];
//    //微信登陆的时候需要初始化
//    [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
//                           appSecret:@"64020361b8ec4c99936c0e3999a9f249"
//                           wechatCls:[WXApi class]];
//    self.window.rootViewController = mainNav;
    [mainVC release];
//    [mainNav release];
    [_window release];
    return YES;
}
- (void)dealloc
{
    [_window release];
    [super dealloc];
}


-(void)showWord1
{
    
    UIImageView *word_ = [[UIImageView alloc]initWithFrame:self.window.bounds];
//    word_.image = [UIImage imageNamed:@"750x1334副本.png"];
    
//    UILabel *word2_ = [[UILabel alloc] initWithFrame:CGRectMake(120, 250, 200, 60)];
//    [word2_ setText:@"BinarySport"];
//    [word2_ setTextColor:[UIColor whiteColor]];
//    [word2_ setFont:[UIFont systemFontOfSize:30]];
    
    [self.window addSubview:word_];
//    [self.window addSubview:word2_];
    
    
    word_.alpha = 1.0;
    [UIView animateWithDuration:0.0f delay:0.0f options:UIViewAnimationOptionCurveLinear
                     animations:^
     {
         word_.alpha = 20;
     }
                     completion:^(BOOL finished)
     {
         [NSThread sleepForTimeInterval:0.0f];
         [self.window removeFromSuperview];
         
         MainPageViewController *mainVC = [[MainPageViewController alloc] init];
         UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC];
         //透明导航栏 需要添加一个图片
         
         [mainNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"beijing0.png"] forBarMetrics:UIBarMetricsCompact];
         mainNav.navigationBar.barStyle = UIBarStyleBlackTranslucent;
         mainNav.extendedLayoutIncludesOpaqueBars = YES;
         RightViewController *leftView = [[[RightViewController alloc] init] autorelease];

             IIViewDeckController *vc = [[IIViewDeckController alloc] initWithCenterViewController:mainNav rightViewController:leftView];
        

//         IIViewDeckController *vc = [[IIViewDeckController alloc] initWithCenterViewController:mainNav rightViewController:leftView];

         vc.rightSize =  (50);
//         self.viewDeckController = vc;
         self.window.rootViewController = vc;
         

         
         
//         UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, self.window.frame.size.height / 6 *5.4, self.window.frame.size.width, self.window.frame.size.height / 6)];

         if([singleSong shareSingleSong].viewNum==1){
         
             UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.window.frame.size.width/6, self.window.frame.size.height)];
             view.backgroundColor=[UIColor blackColor];
             [self.window addSubview:view];
             
             [self.window bringSubviewToFront:view];
         
         }
         

         UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, self.window.frame.size.height *607.5/667 , self.window.frame.size.width, self.window.frame.size.height *60/ 667)];

         view1.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"beijing"]];
         view1.alpha=0.8;
         view1.tag=1001;
         [self.window addSubview:view1];
         [self.window bringSubviewToFront:view1];
        
         NSNotificationCenter *center1=[NSNotificationCenter  defaultCenter];
         [center1 addObserver:self selector:@selector(hidden) name:@"隐藏" object:nil];
         
         
         NSNotificationCenter *center2=[NSNotificationCenter  defaultCenter];
         [center2 addObserver:self selector:@selector(Nohidden) name:@"不隐藏" object:nil];
         
         NSNotificationCenter *center3=[NSNotificationCenter  defaultCenter];
         [center3 addObserver:self selector:@selector(mvBU) name:@"暂停" object:nil];
         


         
         //播放 暂停按钮
         self.play=[UIButton buttonWithType:UIButtonTypeSystem];
        // _play.frame=CGRectMake(180, 10, 45, 45);
     _play.frame=CGRectMake(view1.frame.size.width * 230 /375,view1.frame.size.height * 10/60, view1.frame.size.width* 40 /375 , view1.frame.size.height* 40/60);
    
         [_play setBackgroundImage:[UIImage imageNamed:@"bofang.png"] forState:UIControlStateNormal];
         [_play addTarget:self
                   action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
         
         [view1 addSubview:_play];
         //调出播放界面
         UIButton *buPlay=[UIButton buttonWithType:UIButtonTypeSystem];
         buPlay.frame=CGRectMake(0,0, view1.frame.size.width* 60 /375 , view1.frame.size.height* 60/60);
         [buPlay setBackgroundImage:[UIImage imageNamed:@"tu.png"] forState:UIControlStateNormal];
         [buPlay addTarget:self action:@selector(createView:) forControlEvents:UIControlEventTouchUpInside];
         [view1 addSubview:buPlay];
         
         UIButton *next=[UIButton buttonWithType:UIButtonTypeSystem];
         next.frame=CGRectMake(view1.frame.size.width * 300 /375,view1.frame.size.height * 20/60, view1.frame.size.width* 25 /375 , view1.frame.size.height* 25/60);
         
         [next setBackgroundImage:[UIImage imageNamed:@"xiayiqu.png"] forState:UIControlStateNormal];
         [next addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
         [view1 addSubview:next];
         
         self.slider1=[[UISlider alloc]initWithFrame:CGRectMake(view1.frame.size.width * 70 / 375 ,0,view1.frame.size.width * 280 / 375,view1.frame.size.height* 10/60)];
         [view1 addSubview:self.slider1];
         _slider1.value=0;
         
         
         [self.slider1 setThumbImage:[UIImage imageNamed:@"12345.png"] forState:UIControlStateHighlighted];
         [self.slider1 setThumbImage:[UIImage imageNamed:@"12345.png"]  forState:UIControlStateNormal];
         
         self.slider1.enabled=NO;
         
         [self.slider1 release];
         
         self.elapsedTime=[[UILabel alloc]initWithFrame:CGRectMake(view1.frame.size.width * 120 / 375 , view1.frame.size.height * 50/(self.window.frame.size.height / 6), view1.frame.size.width * 50 / 375, view1.frame.size.height * 20/(self.window.frame.size.height / 6))];
         [view1 addSubview:_elapsedTime];
         self.elapsedTime.hidden=YES;
         self.Time=[[UILabel alloc]initWithFrame:CGRectMake(view1.frame.size.width * 240 / 375 , view1.frame.size.height * 50/(self.window.frame.size.height / 6), view1.frame.size.width * 50 / 375, view1.frame.size.height * 20/(self.window.frame.size.height / 6))];
         [view1 addSubview:_Time];
         self.Time.hidden=YES;
         NSNotificationCenter *center=[NSNotificationCenter  defaultCenter];
         [center addObserver:self selector:@selector(receivenotification) name:@"播放" object:nil];
         
         self.timeRemaining=[[UILabel alloc]initWithFrame:CGRectMake(view1.frame.size.width * 200 / 375, view1.frame.size.height * 600 / 667, view1.frame.size.width * 160 / 375, view1.frame.size.height * 30 / 667)];
         
         [view1 addSubview:self.timeRemaining];
         self.timeRemaining.hidden=YES;
         [self.timeRemaining release];
         
         self.songLabel1=[[UILabel alloc]initWithFrame:CGRectMake(view1.frame.size.width * 70 / 375 , view1.frame.size.height * 10/60, view1.frame.size.width *150 / 375, view1.frame.size.height * 25/60)];
      
         
         [view1 addSubview:self.songLabel1];
         [self.songLabel1 release];
         
//         self.singerLabel1=[[UILabel alloc]initWithFrame:CGRectMake(70, 40, 100, 15)];
      self.singerLabel1=[[UILabel alloc]initWithFrame:CGRectMake(view1.frame.size.width * 70 / 375 , view1.frame.size.height * 35/60, view1.frame.size.width *150 / 375, view1.frame.size.height * 25/60)];
         
         [view1 addSubview:self.singerLabel1];
         [self.singerLabel1 release];
         
         
         
         //播放界面
#pragma mark -播放界面
         
         UIView *view2=[[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
         
         view2.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bujing.png"]];
         view2.tag=1000;
         [self.window addSubview:view2];
         view2.hidden=YES;
         
//         self.button=[UIButton buttonWithType:UIButtonTypeSystem];
//         self.button.frame=CGRectMake(view2.frame.size.width * 147.5 / 375, view2.frame.size.height * 550 / 667, view2.frame.size.width * 80 / 375, view2.frame.size.height * 80 / 667);
//           [self.button setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];
//         [view2 addSubview:self.button];
         
         //上一曲
         UIButton *bulast=[UIButton buttonWithType:UIButtonTypeSystem];
         bulast.frame=CGRectMake(view2.frame.size.width * 75 / 375, view2.frame.size.height * 583 / 667, view2.frame.size.width * 30 / 375, view2.frame.size.height * 20 / 667);
         [bulast setBackgroundImage:[UIImage imageNamed:@"shangyiqu"] forState:UIControlStateNormal];
         [bulast addTarget:self action:@selector(last) forControlEvents:UIControlEventTouchUpInside];
         [view2 addSubview:bulast];
         
         //下一曲
         self.bunext=[UIButton buttonWithType:UIButtonTypeSystem];
         _bunext.frame=CGRectMake(view2.frame.size.width * 265 / 375, view2.frame.size.height * 583 / 667, view2.frame.size.width * 30 / 375, view2.frame.size.height * 20 / 667);
         [_bunext setBackgroundImage:[UIImage imageNamed:@"xiayiqu"] forState:UIControlStateNormal];
         [_bunext addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
         [view2 addSubview:_bunext];
         
         //播放
         self.playButton=[UIButton buttonWithType:UIButtonTypeSystem];
         self.playButton.frame=CGRectMake(view2.frame.size.width * 147.5 / 375, view2.frame.size.height * 550 / 667, view2.frame.size.width * 80 / 375, view2.frame.size.height * 80 / 667);
         self.playButton.layer.cornerRadius=50;
         [self.playButton addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
         [self.playButton setBackgroundImage:[UIImage imageNamed:@"bofang.png"] forState:UIControlStateNormal];
         [view2 addSubview:self.playButton];
         
         
         _bu=[UIButton buttonWithType:UIButtonTypeSystem];
        // _bu.frame=CGRectMake(280, 170, 30, 30);
         _bu.frame=CGRectMake(view2.frame.size.width * 320 / 375, view2.frame.size.height * 170 / 667, view2.frame.size.width * 30 / 375, view2.frame.size.height * 30/ 667);
         [_bu setBackgroundImage:[UIImage imageNamed:@"shunxu.png"] forState:UIControlStateNormal];
         
         [view2 addSubview:self.bu];
         
         //播放类型
         _palyType=[UIButton buttonWithType:UIButtonTypeSystem];
         _palyType.frame=CGRectMake(view2.frame.size.width * 320 / 375, view2.frame.size.height * 170 / 667, view2.frame.size.width * 30 / 375, view2.frame.size.height * 30/ 667);
         [_palyType addTarget:self action:@selector(playType) forControlEvents:UIControlEventTouchUpInside];
         [view2 addSubview:_palyType];
         
         self.alterRefuse=[[UIAlertView alloc]initWithTitle:@"播放模式" message:@"单曲循环" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
         
         
         self.alterRandom=[[UIAlertView alloc]initWithTitle:@"播放模式" message:@"随机播放" delegate:self cancelButtonTitle:@"确定"otherButtonTitles:nil, nil];
         
         self.alterOrder=[[UIAlertView alloc]initWithTitle:@"播放模式" message:@"顺序播放" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
         
         [view2 addSubview:self.alterOrder];
         [view2 addSubview:self.alterRandom];
         [view2 addSubview:self.alterRefuse];
         
         
         
         //分享按钮
         self.shareButton=[UIButton buttonWithType:UIButtonTypeCustom];
        // self.shareButton.frame=CGRectMake(280, 110, 30, 30);
       self.shareButton.frame=CGRectMake(view2.frame.size.width * 320 / 375, view2.frame.size.height * 110 / 667, view2.frame.size.width * 30 / 375, view2.frame.size.height * 30/ 667);
         [self.shareButton setImage:[UIImage imageNamed:@"fenxiang1.png"] forState:UIControlStateNormal];
         
         [self.shareButton addTarget:self action:@selector(touch) forControlEvents:UIControlEventTouchUpInside];
         [view2 addSubview:self.shareButton];
         
         //滑块
         self.slider=[[UISlider alloc]initWithFrame:CGRectMake(view2.frame.size.width * 30 / 375, view2.frame.size.height * 450 / 667, view2.frame.size.width * 316 / 375, view2.frame.size.height * 20 / 667)];
         
         _slider.value=0;
         [self.slider setMinimumTrackImage:[UIImage imageNamed:@"tiao.png"] forState:UIControlStateNormal];
         [self.slider setMaximumTrackImage:[UIImage imageNamed:@"tiao.png"] forState:UIControlStateNormal];
         [self.slider setThumbImage:[UIImage imageNamed:@"huakuai.png"] forState:UIControlStateHighlighted];
         [self.slider setThumbImage:[UIImage imageNamed:@"huakuai.png"]  forState:UIControlStateNormal];
         [self.slider  addTarget:self action:@selector(songTime1:) forControlEvents:UIControlEventValueChanged];
         
         [view2 addSubview:self.slider];
         [self.slider release];
         
         
         self.elapsedTime1=[[UILabel alloc]initWithFrame:CGRectMake(view2.frame.size.width * 30 / 375, view2.frame.size.height * 450 / 667+25, view2.frame.size.width * 80 / 375, view2.frame.size.height * 20 / 667)];
         [view2 addSubview:self.elapsedTime1 ];
         
         self.Time1=[[UILabel alloc]initWithFrame:CGRectMake(view2.frame.size.width * 290 / 375, view2.frame.size.height * 450 / 667+25, view2.frame.size.width * 80 / 375, view2.frame.size.height * 20 / 667)];
         
         [view2 addSubview:self.Time1];
         
         self.songLabel=[[UILabel alloc]initWithFrame:CGRectMake(view2.frame.size.width * 87.5 / 375, view2.frame.size.height * 40 / 667+64, view2.frame.size.width * 200 / 375, view2.frame.size.height * 40 / 667)];
         self.songLabel.font=[UIFont systemFontOfSize:18];
         self.songLabel.textAlignment=1;
         [view2 addSubview:self.songLabel];
         [_songLabel release];
         self.singerLabel=[[UILabel alloc]initWithFrame:CGRectMake(view2.frame.size.width * 107.5 / 375, view2.frame.size.height * 10 / 667+64, view2.frame.size.width * 160 / 375, view2.frame.size.height * 30 / 667)];
         self.singerLabel.textAlignment=1;
         [view2 addSubview:self.singerLabel];
         [self.singerLabel release];
         
         //收藏按钮
         UIButton *bu=[UIButton buttonWithType:UIButtonTypeSystem];
        // bu.frame=CGRectMake(280, 50, 35, 35);
          bu.frame=CGRectMake(view2.frame.size.width * 320 / 375, view2.frame.size.height * 50 / 667, view2.frame.size.width * 35 / 375, view2.frame.size.height * 35/ 667);
         [bu setBackgroundImage:[UIImage imageNamed:@"shoucang1.png"] forState:UIControlStateNormal];
         [bu addTarget:self action:@selector(touchcollect) forControlEvents:UIControlEventTouchUpInside];
         
         [view2 addSubview:bu];
         
         UIView *viewRoll=[[UIView alloc]initWithFrame:CGRectMake(view2.frame.size.width * 87.5 / 375, view2.frame.size.height * 190 / 667, view2.frame.size.width * 200 / 375, view2.frame.size.height * 200 / 667)];
         UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, view2.frame.size.width * 200 / 375, view2.frame.size.height * 200 / 667)];
         [image setImage:[UIImage imageNamed:@"tu.png"]];
         [viewRoll addSubview:image];
         viewRoll.layer.cornerRadius=100;
         [view2 addSubview:viewRoll];
         [viewRoll release];
         
         //返回按钮
         UIButton *buback=[UIButton buttonWithType:UIButtonTypeSystem];
         //buback.frame=CGRectMake(0, 20, 40, 30);
          buback.frame=CGRectMake(0, view2.frame.size.height * 30/ 667, view2.frame.size.width * 40 / 375, view2.frame.size.height * 30/ 667);
         [buback setBackgroundImage:[UIImage imageNamed:@"fanhui.png"] forState:UIControlStateNormal];
         [buback addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
         [view2 addSubview:buback];
         
         
     }
     ];
}
-(void)playType{
    _bu.hidden=YES;
    switch (self.flag1) {
        case 0:
            [_palyType  setBackgroundImage:[UIImage imageNamed:@"xunhuan.png"] forState:UIControlStateNormal];
            //实现单曲循环
            [self.alterRefuse show];
            
            self.flag1=2;
            self.flag2=1;
            break;
            
        case 2:
            [_palyType  setBackgroundImage:[UIImage imageNamed:@"shunxu.png"] forState:UIControlStateNormal];
            [self.alterOrder show];
            self.flag1=0;
            self.flag2=2;
            self.flag3=2;
            break;
            
    }
    
    
    
    
}

-(void)receivenotification{
    [[AFSoundManager sharedManager]pause];
    self.arr=[[singleSong shareSingleSong]arrSong];
    self.num=[[singleSong shareSingleSong]num];
  if(self.arr.count!=0){
        SongModel *song=self.arr[self.num];
        self.song=song;
        NSString*str=song.url;
        _singerLabel.text=song.singer_name;
        _songLabel.text=song.song_name;
        _singerLabel1.text=song.singer_name;
        _songLabel1.text=song.song_name;
        
        
        [[AFSoundManager sharedManager]startStreamingRemoteAudioFromURL:str  andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
            NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
            [formatter setDateFormat:@"mm:ss"];
            NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
             [self.play setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];
                [self.playButton setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];
            _elapsedTime.text = [formatter stringFromDate:elapsedTimeDate];
            _elapsedTime1.text=_elapsedTime.text;
            if (timeRemaining >0) {
                
                
                CGFloat time=  elapsedTime+timeRemaining;
                NSDate *timeall = [NSDate dateWithTimeIntervalSince1970:time];
                
                _Time.text = [formatter stringFromDate:timeall];
            }
            _Time1.text=_Time.text;
            NSDate *timeRemainingDate = [NSDate dateWithTimeIntervalSince1970:timeRemaining];
            _timeRemaining.text = [formatter stringFromDate:timeRemainingDate];
            if([_timeRemaining.text isEqualToString:@"00:01"]){
                if(self.flag2==1){
                    [[AFSoundManager sharedManager]restart];
                }
                if(self.flag1==0){
                    if(_num<self.arr.count-1){
                        [self next];
                        
                    }
                    if (_num==self.arr.count-1) {
                        [[AFSoundManager sharedManager]stop];
                        
                    }
                }
            }
            if([_timeRemaining.text isEqualToString:@"00:00" ]&&![_elapsedTime.text  isEqual:@"00:00"]){
                [[AFSoundManager sharedManager]pause ];
            }
            
            
            _slider1.value = percentage * 0.01;
            _slider.value=percentage * 0.01;
        }
         ];}
    
}
-(void)mvBU{
   
    self.flag=0;
    [self action];
}
-(void)action
{
    [self.play setBackgroundImage:[UIImage imageNamed:@"bofang"] forState:UIControlStateNormal];
  
    if (self.flag==0) {
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"bofang.png"] forState:UIControlStateNormal];
        [[AFSoundManager sharedManager]pause];
        
        self.flag=1;
    } else {
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];
         [self.play setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];        [[AFSoundManager sharedManager]resume];
        self.flag=0;
    }
    
}

-(void)last
{
    if(_num> 0){
        
        _num--;
        [[AFSoundManager sharedManager]pause];
    
        if(self.arr.count!=0){
            SongModel *song=self.arr[self.num];
            self.song=song;
            NSString*str=song.url;
            _singerLabel.text=song.singer_name;
            _songLabel.text=song.song_name;
            _singerLabel1.text=song.singer_name;
            _songLabel1.text=song.song_name;
            
            
            [[AFSoundManager sharedManager]startStreamingRemoteAudioFromURL:str  andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
                NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
                [formatter setDateFormat:@"mm:ss"];
                NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
                [self.play setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];
                [self.playButton setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];
                _elapsedTime.text = [formatter stringFromDate:elapsedTimeDate];
                _elapsedTime1.text=_elapsedTime.text;
                if (timeRemaining >0) {
                    
                    
                    CGFloat time=  elapsedTime+timeRemaining;
                    NSDate *timeall = [NSDate dateWithTimeIntervalSince1970:time];
                    
                    _Time.text = [formatter stringFromDate:timeall];
                }
                _Time1.text=_Time.text;
                NSDate *timeRemainingDate = [NSDate dateWithTimeIntervalSince1970:timeRemaining];
                _timeRemaining.text = [formatter stringFromDate:timeRemainingDate];
                if([_timeRemaining.text isEqualToString:@"00:01"]){
                    if(self.flag2==1){
                        [[AFSoundManager sharedManager]restart];
                    }
                    if(self.flag1==0){
                        if(_num<self.arr.count-1){
                            [self next];
                            
                        }
                        if (_num==self.arr.count-1) {
                            [[AFSoundManager sharedManager]stop];
                            
                        }
                    }
                }
                if([_timeRemaining.text isEqualToString:@"00:00" ]&&![_elapsedTime.text  isEqual:@"00:00"]){
                    [[AFSoundManager sharedManager]pause ];
                }
                
                
                _slider1.value = percentage * 0.01;
                _slider.value=percentage * 0.01;
            }
             ];}
        
        
    }
}

-(void)next{
    if(self.arr.count==1){
        return;
    }
    if(_num<= self.arr.count-2){
        
        self.num++;
    }
    //    [[AFSoundManager sharedManager]pause];
    //    SongModel *song=self.arr[self.num];
    //    NSString*str=song.url;
    //      _singerLabel.text=song.singer_name;
    //    _songLabel.text=song.song_name;
    //    [[AFSoundManager sharedManager]startStreamingRemoteAudioFromURL:str  andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
    //
    //        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    //        [formatter setDateFormat:@"mm:ss"];
    //
    //        NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
    //        _elapsedTime.text = [formatter stringFromDate:elapsedTimeDate];
    //        if (timeRemaining>0) {
    //
    //
    //        CGFloat time=  elapsedTime+timeRemaining;
    //        NSDate *timeall = [NSDate dateWithTimeIntervalSince1970:time];
    //        _Time.text = [formatter stringFromDate:timeall];
    //    }
    //
    //
    //
    //        _slider1.value = percentage * 0.01;
    //        _slider.value=percentage * 0.01;
    //    }     ];
         [[AFSoundManager sharedManager]pause];
    if(self.arr.count>=2){
        SongModel *song=self.arr[self.num];
        self.song=song;
        NSString*str=song.url;
        _singerLabel.text=song.singer_name;
        _songLabel.text=song.song_name;
        _singerLabel1.text=song.singer_name;
        _songLabel1.text=song.song_name;
        
        [[AFSoundManager sharedManager]startStreamingRemoteAudioFromURL:str  andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
            NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
            [formatter setDateFormat:@"mm:ss"];
            [self.play setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];
                [self.playButton setBackgroundImage:[UIImage imageNamed:@"tingzhi.png"] forState:UIControlStateNormal];
            NSDate *elapsedTimeDate = [NSDate dateWithTimeIntervalSince1970:elapsedTime];
            
            _elapsedTime.text = [formatter stringFromDate:elapsedTimeDate];
            _elapsedTime1.text=_elapsedTime.text;
            if (timeRemaining >0) {
                
                
                CGFloat time=  elapsedTime+timeRemaining;
                NSDate *timeall = [NSDate dateWithTimeIntervalSince1970:time];
                
                _Time.text = [formatter stringFromDate:timeall];
            }
            _Time1.text=_Time.text;
            NSDate *timeRemainingDate = [NSDate dateWithTimeIntervalSince1970:timeRemaining];
            _timeRemaining.text = [formatter stringFromDate:timeRemainingDate];
            if([_timeRemaining.text isEqualToString:@"00:01"]){
                if(self.flag2==1){
                    [[AFSoundManager sharedManager]restart];
                }
                if(self.flag1==0){
                    if(_num<self.arr.count-1){
                        [self next];
                        
                    }
                    if (_num==self.arr.count-1) {
                        [[AFSoundManager sharedManager]stop];
                        
                    }
                }
            }
            if([_timeRemaining.text isEqualToString:@"00:00" ]&&![_elapsedTime.text  isEqual:@"00:00"]){
                [[AFSoundManager sharedManager]pause ];
            }
            
            
            _slider1.value = percentage * 0.01;
            _slider.value=percentage * 0.01;
        }
         ];
    }
    
    if(_num==self.arr.count-1){
        
    }
    
}
-(void)songTime1:(UISlider *)sender
{
    [[AFSoundManager sharedManager]moveToSection:sender.value];
}
-(void)createView:(UIButton *)sender{
    CATransition *animation = [CATransition animation];
    animation.type = kCATransitionMoveIn;
    
    [[self.window viewWithTag:1000].layer addAnimation:animation forKey:nil];
    
    [self.window viewWithTag:1000].hidden=NO;
}
-(void)back:(UIButton*)sender{
    CATransition *animation = [CATransition animation];
    animation.type = kCATransitionPush;
    
    [ [self.window viewWithTag:1000].layer addAnimation:animation forKey:nil];
    
    [self.window viewWithTag:1000].hidden=YES;
    
}
- (void)touch{
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ShareSDK" ofType:@"png"];
    
    NSString *str =self.song.song_name;
    NSString *str1 = self.song.singer_name;
    NSString *str3 = self.song.url;
    NSString *str2 = [NSString stringWithFormat:@"我在听《%@-%@》,你也来听吧! %@（分享自@1丶year 音乐客户端）",str,str1,str3];
    NSLog(@"%@",str);
    // 构造分享内容
    id<ISSContent> publishContent = [ShareSDK content:str2
                                       defaultContent:@"测试一下"
                                                image:[ShareSDK imageWithPath:imagePath]
                                                title:@"ShareSDK"
                                                  url:@"http://www.mob.com"
                                          description:@"这是一条测试信息"
                                            mediaType:SSPublishContentMediaTypeNews];
    //创建弹出菜单容器
    id<ISSContainer> container = [ShareSDK container];
    //    [container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];
    
    //弹出分享菜单
    if(self.song.song_name!=nil){
        [ShareSDK showShareActionSheet:container
                             shareList:nil
                               content:publishContent
                         statusBarTips:YES
                           authOptions:nil
                          shareOptions:nil
                                result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                    
                                    if (state == SSResponseStateSuccess)
                                    {
                                        NSLog(NSLocalizedString(@"TEXT_ShARE_SUC", @"分享成功"));
                                        UIAlertView *aler = [[UIAlertView alloc] initWithTitle:@"提示" message:@"分享成功" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil,nil];
                                        [aler show];
                                        [aler release];
                                        
                                    }
                                    else if (state == SSResponseStateFail)
                                    {
                                        NSLog(NSLocalizedString(@"TEXT_ShARE_FAI", @"分享失败,错误码:%d,错误描述:%@"), [error errorCode], [error errorDescription]);
                                    }
                                }];
    }
}
// 收藏
- (void)touchcollect{
    [[Singleton shareSingleton] openDB];
    [[Singleton shareSingleton] createTable];
    
    
    int flag = 0;
    NSMutableArray *arr = [[Singleton shareSingleton] selectLand];
    
    for (Code *code in arr) {
        if ([code.songName isEqualToString:self.song.song_name]) {
            // [self showMessage:@"已收藏"];
            NSLog(@"已经收藏");
            UIAlertView *aler = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已经收藏" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil,nil];
            [aler show];
            [aler release];
            
            flag = 1;
        }
    }
    if(flag == 0){
        //插入数据
        if(self.song.song_name!=nil){
            Code *code = [[Code alloc] init];
            code.songName = self.song.song_name;
            code.singerName = self.song.singer_name;
            code.url = self.song.url;
            [[Singleton shareSingleton] insertLand:code];
            
            UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake([self.window viewWithTag:1000].frame.size.width/2-75, [self.window viewWithTag:1000].frame.size.height/2-32.5, 150, 65)];
            view2.backgroundColor = [UIColor whiteColor];
            view2.alpha = 0.8;
            UILabel *label = [[UILabel alloc] init];
            label.text = @"收藏成功";
            label.textAlignment = NSTextAlignmentCenter;
            label.frame = CGRectMake(view2.frame.size.width/2-50, view2.frame.size.height/2-20, 100, 40);
            [view2 addSubview:label];
            
            [[self.window viewWithTag:1000] addSubview:view2];
            [UIView animateWithDuration:2 animations:^{
                view2.alpha = 0;
            } completion:^(BOOL finished) {
                [view2 removeFromSuperview];
            }];
            
            [label release];
            [view2 release];
            
            
            
            
            
            
            
        }
        
    }
    
}
-(void)hidden{

    [self.window viewWithTag:1001].hidden=YES;
}
-(void)Nohidden{
   [self.window viewWithTag:1001].hidden=NO;
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
